home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / dsp / 56000tar.z / 56000tar / 56000 / telecom / viterbi / decode.asm < prev    next >
Assembly Source File  |  1992-04-28  |  11KB  |  549 lines

  1. ;This program is a Viterbi Decoder for V.32.  There is a 16
  2. ;time period delay which will approach the maximum possible 
  3. ;gain for this type of encoder.
  4.     page 132,66,3,3,0
  5.     opt cex
  6.     org l:$0000
  7.  
  8. period    dsm      128
  9. location dsm    32
  10. input    dsm    16
  11. tables    dsm    8
  12. temp    dsm    8
  13. endlong    equ    *
  14.     org x:endlong
  15. storr6    ds    1
  16.     org x:512
  17. boundry1    ds    32
  18. boundry2    ds    32
  19. boundry3    ds    32
  20. boundry4    ds    32
  21. boundry5    ds    32
  22. boundry6    ds    32
  23. boundry7    ds    32
  24. boundry8    ds    32
  25. boundry9    ds    32
  26. boundry10    ds    32
  27. boundry11    ds    32
  28. boundry12    ds    32
  29. boundry13    ds    32
  30.  
  31. start    equ    $40
  32. four    equ     $200000
  33. three    equ    $180000
  34. two    equ    $100000
  35. one    equ    $080000
  36. zero    equ    $000000
  37. mone    equ    $f80000
  38. mtwo    equ    $f00000
  39. mthree    equ    $e80000
  40. mfour    equ    $e00000
  41. large    equ    .9
  42. small    equ    .1
  43. offset    equ    $010000
  44.  
  45.     org    p:start
  46.     jsr     initialize
  47.     do     #115,endrun
  48.     jsr    readdata
  49.     jsr    findmindist
  50.     jsr    accumdist
  51.     jsr    traceback
  52.     jsr     outputdata
  53. endrun
  54.  
  55. ;this initialization routine initializes register and modifiers
  56. ;as well as clearing the memeory.
  57. ;the constellation is also loaded into memory here.
  58. ;the accumulated distance array is set so that state zero starts out
  59. ;at a value of zero and all others start out larger, forcing the paths
  60. ;to merge at the zero states.
  61.  
  62. initialize
  63.     move    #127,m1
  64.     move    #127,m5
  65.     move    #15,m6
  66.     move    #0,r1
  67.     clr     b       #$0,r0
  68.     clr     a    r0,r5
  69.     do #256,clrmem
  70.     move     a,x:(r0)+    b,y:(r5)+
  71. clrmem
  72.     move     #tables+1,r7
  73.     move    #$400000,a1
  74.     rep #7
  75.     move     a1,x:(r7)+
  76.  
  77.     move    #input,b1
  78.     move    b1,x:storr6  
  79.  
  80.  
  81. ;Now load full scale values of the constellationin the table location.
  82.   
  83.  
  84.     move     #location,r0
  85.     move     r0,r4
  86.     move     #mfour,a
  87.     move    #one,b
  88.     move     a,x:(r0)+    b,y:(r4)+    
  89.     move     #zero,a
  90.     move    #mthree,b    
  91.     move    a,x:(r0)+    b,y:(r4)+
  92.     move    #one,b
  93.     move    a,x:(r0)+    b,y:(r4)+
  94.     move      #four,a           
  95.     move    a,x:(r0)+    b,y:(r4)+
  96.     move       #mone,b
  97.     move     a,x:(r0)+    b,y:(r4)+
  98.     move    #zero,a
  99.     move    #three,b
  100.     move    a,x:(r0)+    b,y:(r4)+ 
  101.     move    #mone,b
  102.     move    a,x:(r0)+    b,y:(r4)+  
  103.     move    #mfour,a
  104.     move    a,x:(r0)+    b,y:(r4)+
  105.     move     #mtwo,a
  106.     move    #three,b
  107.     move    #mone,y1
  108.     move    a,x:(r0)+    b,y:(r4)+
  109.     move    a,x:(r0)+    y1,y:(r4)+
  110.     move    #two,a
  111.     move    a,x:(r0)+    b,y:(r4)+
  112.     move    a,x:(r0)+    y1,y:(r4)+
  113.     move    #one,b
  114.     move    #mthree,y1
  115.     move    a,x:(r0)+    y1,y:(r4)+
  116.     move    a,x:(r0)+    b,y:(r4)+
  117.     move    #mtwo,a
  118.     move    a,x:(r0)+    y1,y:(r4)+
  119.     move    a,x:(r0)+    b,y:(r4)+
  120.     move    #one,a
  121.     move    a,x0
  122.     move    #mthree,a
  123.     move    #two,b
  124.     move    b,y0
  125.     move    #mtwo,b
  126.     move    a,x:(r0)+    b,y:(r4)+
  127.     move    x0,x:(r0)+    b,y:(r4)+
  128.     move    a,x:(r0)+    y0,y:(r4)+
  129.     move    x0,x:(r0)+    y0,y:(r4)+
  130.     move     #three,a
  131.     move    a,x0
  132.     move    #mone,a
  133.     move    x0,x:(r0)+    y0,y:(r4)+
  134.     move    a,x:(r0)+    y0,y:(r4)+
  135.     move    x0,x:(r0)+    b,y:(r4)+
  136.     move    a,x:(r0)+    b,y:(r4)+
  137.     move    #one,a
  138.     move    #zero,b
  139.     move    b,y0
  140.     move    #four,b
  141.     move    a,x:(r0)+    b,y:(r4)+
  142.     move    #mthree,x0
  143.     move    x0,x:(r0)+    y0,y:(r4)+
  144.     move    a,x:(r0)+    y0,y:(r4)+
  145.     move    #mfour,b
  146.     move    a,x:(r0)+    b,y:(r4)+
  147.     move    #mone,a
  148.     move    a,x:(r0)+    b,y:(r4)+
  149.     move    #three,x0
  150.     move    x0,x:(r0)+    y0,y:(r4)+
  151.     move    a,x:(r0)+    y0,y:(r4)+ 
  152.     move    #four,b
  153.     move    a,x:(r0)+    b,y:(r4)+
  154.     rts
  155.  
  156. ;readdata reads in the data from a simulator file.  Since it is read in as
  157. ;a point on the constellation, it must be converted to real and imaginary
  158. ;componenets by indexing into a table.
  159. ;it is also offfset by a value "offset" so it is not considered to be perfect
  160. ;data.
  161.  
  162. readdata
  163.     move    y:$efe,a
  164.     move    a,n2
  165.     move    #location,r2
  166.     move    x:storr6,r6
  167.     lua    (r2)+n2,r4
  168.     move    #>offset,x0
  169.     move    x:(r4),a
  170.     add    x0,a    y:(r4),b
  171.     add    x0,b     a,x:(r6)
  172.     move    b,y:(r6)+
  173.     move    r6,x:storr6
  174.     rts
  175.  
  176. ;the minimum distance is found to the closest point in every state and stored.
  177. ;the values are stored so that indexing is made easier, state 0,2,3,1,4,7,6,5.
  178. ;this will greatly reduce the number of cycles needed later.
  179. ;a smoothing function is used to accumulate distances in the accumulated    
  180. ;table so this minimum distance is multiplied by .1.
  181.  
  182. findmindist
  183.     
  184.     move    x:-(r6),a    
  185.     move    #one,x0
  186.     cmpm    x0,a    y:(r6),b
  187.     jgt    bigone    ;x>1
  188.     cmpm    x0,b    #boundry1,r2
  189.     jlt    continue    ;x<1,y<1, load r2 with boundry 1 and continue
  190.     move    #two,x1
  191.     cmpm    x1,b    #boundry4,r2
  192.     jlt    continue    ;x<1,y>1andy<2, load r2 with boundry4, go on
  193.     move    #boundry6,r2
  194.     jmp    continue    ;x<1,y>2, load r2 with boundry6 and continue
  195. bigone    move #two,x1    
  196.     cmpm    x1,a
  197.     jgt    bigtwo        ;x>2, jmp to that case
  198.     cmpm    x0,b    #boundry2,r2
  199.     jlt    continue    ;x>1 ans x<2, y<1 load boundry2 and continue
  200.     cmpm    x1,b    #boundry5,r2
  201.     jlt    continue    ;x>1,y<2 load boundry 5 and continue
  202. bigtwo    cmpm    x0,b    #boundry3,r2
  203.     jlt    continue    ;x>2 and y<1 so load boundry3 and continue
  204.     abs    a    #two,y0
  205.     abs    b    a,x1
  206.     sub    y0,a    b,y1    
  207.     sub    x0,b
  208.     cmpm    a,b    y1,b
  209.     jgt    greatery1
  210.     cmp    y0,b    #boundry7,r2
  211.     jlt    continue 
  212.     move    #boundry12,r2
  213.     jmp    continue
  214. greatery1    sub    y0,b    x1,a    
  215.     sub    x0,a    
  216.     cmpm    a,b    x1,a    
  217.     jgt    greatery2
  218.     cmp    y0,a    #boundry10,r2
  219.     jlt    continue
  220.     move    y1,b
  221.     cmp    y0,b    #boundry11,r2
  222.     jlt    continue
  223.     move    #boundry9,r2
  224.     jmp    continue
  225. greatery2    cmp    y0,a    #boundry8,r2
  226.     jlt    continue
  227.     move    #boundry13,r2
  228. continue    clr    a    x:(r6),x1
  229.     cmp    x1,a    y:(r6),y1
  230.     jgt    negx
  231.     cmp    y1,a    #24,n2
  232.     jgt    posxnegy
  233. posxposy    jmp findist
  234. posxnegy    move    x:(r2)+n2,x0    ;update r2 by 24
  235.     jmp findist
  236. negx    cmp    y1,a    #8,n2
  237.     jgt    negxnegy
  238. negxposy    move    x:(r2)+n2,x0    ;update r2 by 8
  239.     jmp findist
  240. negxnegy    move    x:(r2)+n2,x0    ;update r2 by 16
  241.     move    x:(r2)+n2,x0
  242. findist
  243.     move    x:(r2)+,r0
  244.     move    #tables,r4
  245.     move    x:(r0),a
  246.     sub    x1,a    y:(r0),b
  247.     sub    y1,b    a,x0
  248.     mpy    x0,x0,a    b,y0
  249.     mac    y0,y0,a    x:(r2)+,r0    
  250.     move    #small,x0    a,y0
  251.     mpy    x0,y0,a    
  252.     move    x:(r0),a    a,y:(r4)+
  253.     sub    x1,a    y:(r0),b
  254.     sub    y1,b    a,x0    y:(r4)+,y0    
  255.     mpy    x0,x0,a    b,y0
  256.     mac    y0,y0,a    x:(r2)+,r0    
  257.     move    #small,x0    a,y0    
  258.     mpy    x0,y0,a    y:(r4)+,b    
  259.     move    x:(r0),a    a,y:(r4)-
  260.     sub    x1,a    y:(r0),b
  261.     sub    y1,b    a,x0    y:(r4)-,y0
  262.     mpy    x0,x0,a    b,y0
  263.     mac    y0,y0,a    x:(r2)+,r0
  264.     move    #small,x0    a,y0
  265.     mpy    x0,y0,a        
  266.     move    x:(r0),a    a,y:(r4)+
  267.     sub    x1,a    y:(r0),b
  268.     sub    y1,b    a,x0
  269.     mpy    x0,x0,a    b,y0
  270.     mac    y0,y0,a    x:(r2)+,r0
  271.     move    #small,x0    a,y0
  272.     mpy    x0,y0,a    
  273.     move    x:(r0),a    a,y:(r4)+
  274.     sub    x1,a    y:(r0),b
  275.     sub    y1,b    a,x0    y:(r4)+,y0
  276.     mpy    x0,x0,a    b,y0
  277.     mac    y0,y0,a    x:(r2)+,r0
  278.     move    #small,x0    a,y0    
  279.     mpy    x0,y0,a    
  280.     move    x:(r0),a    a,y:(r4)+
  281.     sub    x1,a    y:(r0),b
  282.     sub    y1,b    a,x0    y:(r4)+,y0
  283.     mpy    x0,x0,a    b,y0
  284.     mac    y0,y0,a        x:(r2)+,r0
  285.     move    #small,x0    a,y0    
  286.     mpy    x0,y0,a        y:(r4)+,b
  287.     move    x:(r0),a    a,y:(r4)-
  288.     sub    x1,a    y:(r0),b
  289.     sub    y1,b    a,x0
  290.     mpy    x0,x0,a    b,y0
  291.     mac    y0,y0,a    x:(r2)+,r0
  292.     move    #small,x0    a,y0
  293.     mpy    x0,y0,a    
  294.     move    x:(r0),a    a,y:(r4)-
  295.     sub    x1,a    y:(r0),b
  296.     sub    y1,b    a,x0
  297.     mpy    x0,x0,a    b,y0
  298.     mac    y0,y0,a    x:(r2)+,r0    
  299.     move    #small,x0    a,y0
  300.     mpy    x0,y0,a
  301.     move    a,y:(r4)
  302.  
  303.  
  304.  
  305.  
  306.     rts  
  307.  
  308. ;the accumulted distance routine  adds the smallest distance from the         
  309. ;previously computed table for all pathes going into a state and     
  310. ;does this for all eight states.
  311. accumdist
  312.     clr    a    #tables,r0
  313.     move    #$7fffff,a1
  314.     move    r0,r4
  315.     move    #temp,r2
  316.     move    #3,m0
  317.     move    m0,m4
  318.     move    #2,n1
  319.     move    n1,n5
  320.     move    r1,r5
  321.  
  322.  
  323.  
  324. ;find minimum distance to state zero
  325.     do    #4,statezero
  326.     move    x:(r0),x0    y:(r4),b
  327.     add    x0,b
  328.     cmp    b,a
  329.     tge    b,a    r0,r3
  330.     tge    b,a    r4,r7
  331.     move    x:(r0)+,x0    y:(r4)+,b
  332. statezero
  333.     move    r3,x:(r1)+n1
  334.     move    a,x:(r2)+    y:(r4)+,b
  335.     clr     a        r7,y:(r5)+n5
  336.     move    #$7fffff,a1
  337.  
  338.  
  339.  
  340. ;find minimum distance to state two 
  341.     do    #4,statetwo
  342.     move    x:(r0),x0    y:(r4),b
  343.     add    x0,b
  344.     cmp    b,a
  345.     tge    b,a    r0,r3
  346.     tge    b,a    r4,r7
  347.     move    x:(r0)+,x0    y:(r4)-,b
  348. statetwo
  349.     move    r3,x:(r1)+n1
  350.     move    a,x:(r2)+    y:(r4)+,b    
  351.     clr    a        r7,y:(r5)+n5
  352.     move    #$7fffff,a1
  353.  
  354. ;find minimum distance to state four 
  355.     do    #4,statefour
  356.     move    x:(r0),x0    y:(r4),b
  357.     add    x0,b
  358.     cmp    b,a
  359.     tge    b,a    r0,r3
  360.     tge    b,a    r4,r7
  361.     move    x:(r0)+,x0    y:(r4)+,b
  362. statefour
  363.     move    r3,x:(r1)+n1
  364.     move    a,x:(r2)+    y:(r4)+,b    
  365.     clr    a        r7,y:(r5)+n5
  366.     move    #$7fffff,a1
  367.  
  368. ;find minimum distance to state six 
  369.     do    #4,statezsix
  370.     move    x:(r0),x0    y:(r4),b
  371.     add    x0,b
  372.     cmp    b,a
  373.     tge    b,a    r0,r3
  374.     tge    b,a    r4,r7
  375.     move    x:(r0)+,x0    y:(r4)-,b
  376. statezsix
  377.     move    r3,x:(r1)-n1
  378.     move    a,x:(r2)+    
  379.     move    r7,y:(r5)
  380.     move    #tables+4,r4
  381.     move    r4,r0
  382.     move    x:(r1)-n1,a    
  383.     clr    a    x:(r1)-,b    
  384.     move    #$7fffff,a1
  385.     move    r1,r5
  386.  
  387. ;find minimum distance to state one 
  388.     do    #4,stateone
  389.     move    x:(r0),x0    y:(r4),b
  390.     add    x0,b
  391.     cmp    b,a
  392.     tge    b,a    r0,r3
  393.     tge    b,a    r4,r7
  394.     move    x:(r0)+,x0    y:(r4)+,b
  395. stateone
  396.     move    r3,x:(r1)+n1
  397.     move    a,x:(r2)+    y:(r4)+,b    
  398.     clr    a    r7,y:(r5)+n5
  399.     move    #$7fffff,a1
  400.  
  401. ;find minimum distance to state three 
  402.     do    #4,statethree
  403.     move    x:(r0),x0    y:(r4),b
  404.     add    x0,b
  405.     cmp    b,a
  406.     tge    b,a    r0,r3
  407.     tge    b,a    r4,r7
  408.     move    x:(r0)+,x0    y:(r4)-,b
  409. statethree
  410.     move    r3,x:(r1)+n1
  411.     move    a,x:(r2)+    y:(r4)+,b    
  412.     clr    a    r7,y:(r5)+n5
  413.     move    #$7fffff,a1
  414.     move    (r4)+
  415.  
  416. ;find minimum distance to state five 
  417.     do    #4,statefive
  418.     move    x:(r0),x0    y:(r4),b
  419.     add    x0,b
  420.     cmp    b,a
  421.     tge    b,a    r0,r3
  422.     tge    b,a    r4,r7
  423.     move    x:(r0)+,x0    y:(r4)-,b
  424. statefive
  425.     move    r3,x:(r1)+n1
  426.     move    a,x:(r2)+    y:(r4)-,b    
  427.     clr    a    r7,y:(r5)+n5
  428.     move    #$7fffff,a1
  429.  
  430. ;find minimum distance to state seven 
  431.     do    #4,stateseven
  432.     move    x:(r0),x0    y:(r4),b
  433.     add    x0,b
  434.     cmp    b,a
  435.     tge    b,a    r0,r3
  436.     tge    b,a    r4,r7
  437.     move    x:(r0)+,x0    y:(r4)+,b
  438. stateseven
  439.     move    r3,x:(r1)+
  440.     move    a,x:(r2)+    y:(r4)+,b    
  441.     clr    b    r7,y:(r5)+
  442.     move    #$7fffff,b1
  443.  
  444. ;now move new accumulated distances into the  accumulated distance
  445. ;table from the temporary table 
  446. ;also find the min distance state and store in r4 which is no longer used
  447.     move    #$ffff,m0
  448.     move    #$ffff,m4
  449.     move    #temp,r3
  450.     move    #tables,r0
  451.     move    #large,x1
  452.     move    #2,n0
  453.     do     #4,endtable
  454.     move    x:(r3)+,x0
  455.     mpy     x1,x0,a
  456.     cmp    a,b    a,x:(r0)+n0
  457.     tge    a,b    r0,r4
  458. endtable
  459.     move    #tables+1,r0
  460.     do    #4,endtablex
  461.     move    x:(r3)+,x0
  462.     mpy    x1,x0,a
  463.     cmp    a,b    a,x:(r0)+n0
  464.     tge    a,b    r0,r4
  465. endtablex
  466. ;store in r0 instead of r4
  467.     
  468.     move    r4,r0
  469.     move    #8,n1
  470.     move      (r0)-n0
  471.     rts
  472.  
  473.  
  474. ;the traceback routine now goes back through every time period starting
  475. ;with the current time period and finds the state from which the path
  476. ;came from one time period previous.  At the end of this search, the
  477. ;last state found will also point to the path at that state, which is the 
  478. ;output  of the trellis.
  479.  
  480. traceback
  481.  
  482. ;find the displacement from the pointer to table and store value in n4
  483.     move    #tables,n0
  484.     move    (r1)-n1
  485.     lua    (r0)-n0,n5
  486.     move    r1,r5
  487.     do    #15,endtrace
  488.     move    (r1)-n1
  489.     move    x:(r5+n5),r0 
  490.     move    r1,r5
  491.     lua    (r0)-n0,n5
  492. endtrace
  493.     move    #location,r0
  494.     move    y:(r5+n5),a
  495.     rts
  496.  
  497. ;the output data routine unscrambles the path order and finds one 
  498. ;of the four points on the constellation coresponding to the output state
  499. ;which is closest to the original input at that time period.
  500.  
  501. outputdata
  502.     move    a,b
  503.     move    #>$b1,x0
  504.     cmp    x0,a    #>$b2,y0    
  505.     teq    y0,b    
  506.     cmp    y0,a    #>$b3,x0    
  507.     teq    x0,b
  508.     cmp    x0,a    #>$b1,y0
  509.     teq    y0,b
  510.     move    #>$b5,x0
  511.     cmp    x0,a    #>$b7,y0
  512.     teq    y0,b
  513.     cmp    y0,a
  514.     teq    x0,b
  515.     move    b,r2
  516.     move    #tables,n2
  517.     move    x:storr6,r6
  518.     lua    (r2)-n2,n3
  519.     move    n3,a
  520.     asl    a
  521.     asl    a
  522.     move     a,n0
  523.     move    r6,r3
  524.     lua    (r0)+n0,r4
  525.     move    #>$7fffff,x1
  526.     move    r4,r0
  527.     do     #4,endout
  528.     move     x:(r3),a    y:(r6),b
  529.     move    x:(r0)+,x0    y:(r4)+,y0
  530.     sub    x0,a
  531.     sub    y0,b    a,x0
  532.     mpy    x0,x0,a    b,y0
  533.     mac    y0,y0,a
  534.     tfr    a,b    x1,a
  535.     cmp    x1,b
  536.     tlt    b,a    r0,r7
  537.     move    a,x1
  538. endout
  539.     clr    a    (r7)-
  540.     move    #location,n0
  541.     move    r7,r0
  542.     move    #$f,a1
  543.     lua    (r0)-n0,r7
  544.     move    r7,x0
  545.     and       x0,a
  546.     move    a1,y:$eff
  547.     rts
  548.  
  549.